var layer;
var $;
var account;
//正则表达式判断字母数字同时存在并不包含特殊字符
var reg =/^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,16}$/;
layui.use(['layer'],function() {
    layer = layui.layer;
    $ = layui.$;

    //获取路由跳转过来的课程·id
    var idArray = window.location.search.split("?");
    account = idArray[1];
    $("#span_account").text(account);

    $('#determine').on('click',function(){
        var pwd=$('#account').val();
        if(pwd!=''&& pwd!=null){
            $.ajax({
                url: '/account/getPassword',
                type: "post",
                dataType: "json",
                data: {"account": account,"conpwd":pwd},
                success: function (data) {
                    if(data==false){
                        if (!reg.exec(pwd)) {
                            $("#prompt").text("密码过于简单");
                        }else{
                            updUserPwd(pwd);
                        }
                    }else{
                        $("#prompt").text("不能与原密码相同");
                    }
                }
            })
        }else{
            $("#prompt").text("密码不能为空");
        }
    })

})

//修改密码
function updUserPwd(conpwd){
    $.ajax({
        url : '/account/setPwd',
        type : "post",
        dataType : "json",
        data : {"newpwd":conpwd,"account":account},
        success : function(data) {
            if(data){
                layer.open({
                    type: 1,
                    skin: 'layui-layer-demo', //样式类名
                    area: ['300px', '200px'],
                    closeBtn: 0, //不显示关闭按钮
                    anim: 2,
                    icon:1,
                    shadeClose: true, //开启遮罩关闭
                    content: '<div style="font-size: 15px; text-align: center; line-height: 80px;">' +
                        '<i class="layui-icon layui-icon-face-smile" style="font-size: 18px; color: #009688;"></i> 修改成功</div>',
                    btn: ['确定'],  //按钮
                    yes: function(){
                        location.href="/login/SyLogin.html";
                    }
                });
            }
        }
    })
}